#!/usr/bin/sh

set -e

echo "[mysqldump]" >> .sqlpwd
echo "user=$JIANMU_USERNAME" >> .sqlpwd
echo "password=$JIANMU_PASSWORD" >> .sqlpwd

mysqldump --defaults-extra-file=.sqlpwd -h ${JIANMU_HOST} -P ${JIANMU_PORT} -u${JIANMU_USERNAME} ${JIANMU_DATABASE} ${JIANMU_TABLES} > ${JM_SHARE_DIR}/${JIANMU_DATABASE}.sql

echo 'result file:'
echo "{\"sql_path\": \"${JM_SHARE_DIR}/${JIANMU_DATABASE}.sql\"}" > /usr/result_file
cat /usr/result_file